gusucode.com > MATLAB与控制系统仿真实践 源代码 > MATLAB与控制系统仿真实践 源代码/第六章/6-2-2/gui_eg5.m

    function varargout = gui_eg5(varargin)
% GUI_EG5 M-file for gui_eg5.fig
%      GUI_EG5, by itself, creates a new GUI_EG5 or raises the existing
%      singleton*.
%
%      H = GUI_EG5 returns the handle to a new GUI_EG5 or the handle to
%      the existing singleton*.
%
%      GUI_EG5('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI_EG5.M with the given input arguments.
%
%      GUI_EG5('Property','Value',...) creates a new GUI_EG5 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before gui_eg5_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to gui_eg5_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help gui_eg5

% Last Modified by GUIDE v2.5 24-Feb-2009 20:38:42

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @gui_eg5_OpeningFcn, ...
                   'gui_OutputFcn',  @gui_eg5_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before gui_eg5 is made visible.
function gui_eg5_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to gui_eg5 (see VARARGIN)

% Choose default command line output for gui_eg5
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes gui_eg5 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = gui_eg5_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function strCode_Callback(hObject, eventdata, handles)
% hObject    handle to strCode (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of strCode as text
%        str2double(get(hObject,'String')) returns contents of strCode as a double


% --- Executes during object creation, after setting all properties.
function strCode_CreateFcn(hObject, eventdata, handles)
% hObject    handle to strCode (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in btnDraw.
function btnDraw_Callback(hObject, eventdata, handles)
%h>> hObject    handle to btnDraw (see GCBO),,h
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

try 
    str=char(get(handles.strCode,'String'));
    str0=[];
    for ii=1:size(str,1)
        str0=[str0,deblank(str(ii,:))];
    end
    eval(str0);
    axes(handles.myAxes);
    plot(x,y);
catch
    errordlg('请重新检查输入数据!');
end

% --- Executes on button press in btnClose.
function btnClose_Callback(hObject, eventdata, handles)
% hObject    handle to btnClose (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close(gcf);


% --- Executes on selection change in lstBox.
function lstBox_Callback(hObject, eventdata, handles)
% hObject    handle to lstBox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns lstBox contents as cell array
%        contents{get(hObject,'Value')} returns selected item from lstBox
v=get(handles.lstBox,'value');

switch v
    case 1,%比例环节
       str1='nump=3;denp=1;';
       str2='t=0:0.1:10;';       
       str3='[y,t,x]=step(nump,denp,t);'; 
       set(handles.strCode,'String',char(str1,str2,str3));
       set(handles.uipanel,'Title','比例环节' );
    case 2,%惯性环节
       str1='numg=1;deng=[0.2 1];';
       str2='t=0:0.1:10;';
       str3='[y,t,x]=step(numg,deng,t);'; 
       set(handles.strCode,'String',char(str1,str2,str3)); 
       set(handles.uipanel,'Title','惯性环节')
    case 3,%比例微分
       str1='K=2;T=0.1;N=5;numpd=[K*T K];denpd=[T/N 1];';
       str2='t=0:0.1:10;';
       str3='[y,t,x]=step(numpd,denpd,t);'; 
       set(handles.strCode,'String',char(str1,str2,str3)); 
       set(handles.uipanel,'Title','比例微分环节');
    case 4,%比例积分
       str1='K=4;T=0.2;numpi=[K*T K];denpi=[T 0];';
       str2='t=0:0.1:10;';
       str3='[y,t,x]=step(numpi,denpi,t);'; 
       set(handles.strCode,'String',char(str1,str2,str3)); 
       set(handles.uipanel,'Title','比例积分环节');
end
% axes(handles.myAxes);
btnDraw_Callback(hObject,eventdata,handles)

% --- Executes during object creation, after setting all properties.
function lstBox_CreateFcn(hObject,eventdata, handles)
% hObject    handle to lstBox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end